home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue44 / system / UMain.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1999-02-28  |  2.5 KB  |  104 lines

  1. unit UMain;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   Menus, StdCtrls, ComCtrls;
  8.  
  9. type
  10.   TPeekForm = class(TForm)
  11.     FormList: TListBox;
  12.     OpenDialog: TOpenDialog;
  13.     Label1: TLabel;
  14.     OpenButton: TButton;
  15.     Label2: TLabel;
  16.     FormData: TRichEdit;
  17.     procedure FormDestroy(Sender: TObject);
  18.     procedure OpenButtonClick(Sender: TObject);
  19.     procedure FormListClick(Sender: TObject);
  20.   private
  21.     { Private declarations }
  22.     hMod: THandle;
  23.     procedure Clear;
  24.     procedure GetResourceInfo;
  25.   public
  26.     { Public declarations }
  27.   end;
  28.  
  29. var
  30.   PeekForm: TPeekForm;
  31.  
  32. implementation
  33.  
  34. {$R *.DFM}
  35.  
  36. function EnumResProc (hMod: THandle; ResType, ResName: PChar; Self: TPeekForm): Boolean; stdcall;
  37. var
  38.     h: THandle;
  39.     p: pDWord;
  40. begin
  41.     // OK - we've got a rc_Data resource, but is it a DFM?
  42.     h := LoadResource (hMod, FindResource (hMod, ResName, ResType));
  43.     p := LockResource (h);
  44.     if p^ = $30465054 then Self.FormList.Items.Add (ResName);
  45.     Result := True;
  46. end;
  47.  
  48. procedure TPeekForm.Clear;
  49. begin
  50.     if hMod > 0 then FreeLibrary (hMod);
  51.     FormData.Lines.Clear;
  52.     FormList.Clear;
  53. end;
  54.  
  55. procedure TPeekForm.GetResourceInfo;
  56. var
  57.     hTemp: THandle;
  58. begin
  59.     hTemp := LoadLibraryEx (PChar (OpenDialog.FileName), 0, Load_Library_As_DataFile);
  60.     if hTemp <> 0 then begin
  61.         Clear;  hMod := hTemp;
  62.         Caption := Format ('Form Peeker - [%s]', [OpenDialog.FileName]);
  63.         EnumResourceNames (hMod, rt_rcData, @EnumResProc, Integer (Self));
  64.         if FormList.Items.Count > 0 then begin
  65.             FormList.ItemIndex := 0;
  66.             FormListClick (Self);
  67.         end;
  68.     end;
  69. end;
  70.  
  71. procedure TPeekForm.FormDestroy (Sender: TObject);
  72. begin
  73.     Clear;
  74. end;
  75.  
  76. procedure TPeekForm.OpenButtonClick(Sender: TObject);
  77. begin
  78.     if OpenDialog.Execute then GetResourceInfo;
  79. end;
  80.  
  81. procedure TPeekForm.FormListClick(Sender: TObject);
  82. var
  83.     sText: TMemoryStream;
  84.     sRes: TResourceStream;
  85. begin
  86.     with FormList do if ItemIndex <> -1 then begin
  87.         sRes := TResourceStream.Create (hMod, Items [ItemIndex], rt_rcData);
  88.         try
  89.             sText := TMemoryStream.Create;
  90.             try
  91.                 ObjectBinaryToText (sRes, sText);
  92.                 sText.Position := 0;
  93.                 FormData.Lines.LoadFromStream (sText);
  94.             finally
  95.                 sText.Free;
  96.             end;
  97.         finally
  98.             sRes.Free;
  99.         end;
  100.     end;
  101. end;
  102.  
  103. end.
  104.